import request from '@/utils/request'
import store from '@/store'
import config from '../utils/config'

export function GetAreaTable (pageSize, currentPage) {
  return request({
    url: '/area/list',
    params: {
      'province-id': store.getters.provinceId,
      'city-id': store.getters.cityId,
      'area-name': store.getters.areaName,
      'join-year': store.getters.joinYear,
      'page-size': pageSize,
      'current-page': currentPage
    },
    method: 'get'
  })
}

export function GetAreaExport () {
  window.open(config.baseUrl + '/area/export?province-id=' + store.getters.provinceId + '&city-id=' + store.getters.cityId + '&area-name=' + store.getters.areaName + '&join-year=' + store.getters.joinYear)
}

export function GetSchoolExport () {
  if (store.getters.roles.indexOf('admin') !== -1) {
    window.open(config.baseUrl + '/school/export?province-id=' + store.getters.provinceId + '&city-id=' + store.getters.cityId + '&area-id=' + store.getters.areaId + '&school-name=' + store.getters.schoolName + '&join-year=' + store.getters.joinYear)
  } else if (store.getters.roles.indexOf('area') !== -1) {
    window.open(config.baseUrl + '/school/export?join-year=' + store.getters.joinYear + '&school-id=' + store.getters.schoolId)
  }
}

export function GetStudentExport () {
  if (store.getters.roles.indexOf('admin') !== -1) {
    window.open(config.baseUrl + '/student/export?province-id=' + store.getters.provinceId + '&city-id=' + store.getters.cityId + '&area-id=' + store.getters.areaId + '&school-name=' + store.getters.schoolName + '&join-year=' + store.getters.joinYear + '&school-roll-id=' + store.getters.schoolRollId)
  } else if (store.getters.roles.indexOf('area') !== -1) {
    window.open(config.baseUrl + '/student/export?join-year=' + store.getters.joinYear + '&school-id' + store.getters.schoolId + '&school-roll-id=' + store.getters.schoolRollId)
  } else if (store.getters.roles.indexOf('school') !== -1) {
    window.open(config.baseUrl + '/student/export?school-roll-id=' + store.getters.schoolRollId)
  }
}

export function GetPhysicalExport () {
  window.open(config.baseUrl + '/physical/export?province-id=' + store.getters.provinceId + '&city-id=' + store.getters.cityId + '&area-id=' + store.getters.areaId + '&school-name=' + store.getters.schoolName + '&join-year=' + store.getters.joinYear + '&school-roll-id=' + store.getters.schoolRollId)
}

export function GetSchoolTable (pageSize, currentPage) {
  if (store.getters.roles.indexOf('admin') !== -1) {
    return request({
      url: '/school/list',
      params: {
        'province-id': store.getters.provinceId,
        'city-id': store.getters.cityId,
        'area-id': store.getters.areaId,
        'school-name': store.getters.schoolName,
        'join-year': store.getters.joinYear,
        'page-size': pageSize,
        'current-page': currentPage
      },
      method: 'get'
    })
  } else if (store.getters.roles.indexOf('area') !== -1) {
    return request({
      url: '/school/list',
      params: {
        'join-year': store.getters.joinYear,
        'school-id': store.getters.schoolId,
        'page-size': pageSize,
        'current-page': currentPage
      },
      method: 'get'
    })
  }
}

export function GetStudentTable (pageSize, currentPage) {
  if (store.getters.roles.indexOf('admin') !== -1) {
    return request({
      url: '/student/list',
      params: {
        'province-id': store.getters.provinceId,
        'city-id': store.getters.cityId,
        'area-id': store.getters.areaId,
        'school-name': store.getters.schoolName,
        'join-year': store.getters.joinYear,
        'school-roll-id': store.getters.schoolRollId,
        'page-size': pageSize,
        'current-page': currentPage
      },
      method: 'get'
    })
  } else if (store.getters.roles.indexOf('area') !== -1) {
    return request({
      url: '/student/list',
      params: {
        'join-year': store.getters.joinYear,
        'school-id': store.getters.schoolId,
        'school-roll-id': store.getters.schoolRollId,
        'page-size': pageSize,
        'current-page': currentPage
      },
      method: 'get'
    })
  } else if (store.getters.roles.indexOf('school') !== -1) {
    return request({
      url: '/student/list',
      params: {
        'school-roll-id': store.getters.schoolRollId,
        'page-size': pageSize,
        'current-page': currentPage
      },
      method: 'get'
    })
  }
}

export function GetPhysicalTable (pageSize, currentPage) {
  return request({
    url: '/physical/list',
    params: {
      'province-id': store.getters.provinceId,
      'city-id': store.getters.cityId,
      'area-id': store.getters.areaId,
      'school-name': store.getters.schoolName,
      'join-year': store.getters.joinYear,
      'school-roll-id': store.getters.schoolRollId,
      'page-size': pageSize,
      'current-page': currentPage
    },
    method: 'get'
  })
}

export function GetLabelTable (pageSize, currentPage) {
  return request({
    url: '/label/list',
    params: {
      'page-size': pageSize,
      'current-page': currentPage
    },
    method: 'get'
  })
}

export function OpenVis (id) {
  window.open(config.baseUrl.replace('api', '') + 'vis?id=' + id)
}

export function OpenApp () {
  window.open(config.baseUrl.replace('api', '') + 'app-management')
}

export function GetReportPackageTable (pageSize, currentPage) {
  if (store.getters.roles.indexOf('admin') !== -1) {
    return request({
      url: '/report/package/list',
      params: {
        'province-id': store.getters.provinceId,
        'city-id': store.getters.cityId,
        'area-id': store.getters.areaId,
        'school-name': store.getters.schoolName,
        'join-year': store.getters.joinYear,
        'page-size': pageSize,
        'current-page': currentPage
      },
      method: 'get'
    })
  } else if (store.getters.roles.indexOf('area') !== -1) {
    return request({
      url: '/report/package/list',
      params: {
        'join-year': store.getters.joinYear,
        'school-id': store.getters.schoolId,
        'page-size': pageSize,
        'current-page': currentPage
      },
      method: 'get'
    })
  }
}

export function GetReportSubTable (pageSize, currentPage) {
  if (store.getters.roles.indexOf('admin') !== -1) {
    return request({
      url: '/report/sub/list',
      params: {
        'province-id': store.getters.provinceId,
        'city-id': store.getters.cityId,
        'area-id': store.getters.areaId,
        'school-name': store.getters.schoolName,
        'join-year': store.getters.joinYear,
        'page-size': pageSize,
        'current-page': currentPage
      },
      method: 'get'
    })
  } else if (store.getters.roles.indexOf('area') !== -1) {
    return request({
      url: '/report/sub/list',
      params: {
        'join-year': store.getters.joinYear,
        'school-id': store.getters.schoolId,
        'page-size': pageSize,
        'current-page': currentPage
      },
      method: 'get'
    })
  }
}

export function makeForRebuildReport (id) {
  return request({
    url: 'report/sub/mark-rebuild',
    params: {
      id: id
    },
    method: 'post'
  })
}

export function GetTagTable (pageSize, currentPage) {
  if (store.getters.roles.indexOf('admin') !== -1) {
    return request({
      url: 'label/tag/list',
      params: {
        'province-id': store.getters.provinceId,
        'city-id': store.getters.cityId,
        'area-id': store.getters.areaId,
        'school-name': store.getters.schoolName,
        'join-year': store.getters.joinYear,
        'school-roll-id': store.getters.schoolRollId,
        'page-size': pageSize,
        'current-page': currentPage
      },
      method: 'get'
    })
  } else if (store.getters.roles.indexOf('area') !== -1) {
    return request({
      url: 'label/tag/list',
      params: {
        'join-year': store.getters.joinYear,
        'school-id': store.getters.schoolId,
        'school-roll-id': store.getters.schoolRollId,
        'page-size': pageSize,
        'current-page': currentPage
      },
      method: 'get'
    })
  } else if (store.getters.roles.indexOf('school') !== -1) {
    return request({
      url: 'label/tag/list',
      params: {
        'school-roll-id': store.getters.schoolRollId,
        'page-size': pageSize,
        'current-page': currentPage
      },
      method: 'get'
    })
  }
}

export function AddTag (studentId, labelId) {
  return request({
    url: 'label/tag',
    method: 'post',
    data: {
      data: [
        {
          studentId: studentId,
          labelId: [labelId]
        }
      ]
    }
  })
}

export function AddTags (data) {
  return request({
    url: 'label/tag',
    method: 'post',
    data: {
      data: data
    }
  })
}

export function DeleteTag (studentId, labelId) {
  return request({
    url: 'label/tag',
    method: 'delete',
    data: {
      data: [
        {
          studentId: studentId,
          labelId: [labelId]
        }
      ]
    }
  })
}

export function DeleteTags (data) {
  return request({
    url: 'label/tag',
    method: 'delete',
    data: {
      data: data
    }
  })
}

export function GetAuthorityTable (pageSize, currentPage) {
  return request({
    url: 'manager/list',
    method: 'get',
    params: {
      'user-name': store.getters.userName,
      'contact-phone': store.getters.contactPhone,
      'page-size': pageSize,
      'current-page': currentPage
    }
  })
}
